﻿from datetime import datetime
from os.path import dirname, join, abspath, exists
from os import getcwd, makedirs
from sys import stderr, __stderr__
from objects import agents

#__dir__ = dirname(abspath(__file__))
__dir__ = getcwd()
path_error = join(__dir__, "agents.log")
filesdir = join(__dir__, "files")
if not exists(filesdir): makedirs(filesdir)
xlsx_file = join(filesdir, "agents.xlsx")
stderr = open(path_error, 'a')
stderr.write("\n\n--------------------------***-----------------------------\nExport has begun...\nLocal Date and Time: "+str(datetime.now())+"\n--------------------------***-----------------------------\n\n")

list=[]
while True:
	list+=[input("Введите код контрагента 1С77:\n")]
	conf=input('Добавить еще одного контрагента? (y (yes), n (no)):\n')
	if 'y' not in conf.lower() and '+' not in conf.lower():
		break

o=agents()
o.write(xlsx_file, o.extract(list))


stderr.write("\nNo errors logged.\n\n\n--------------------------***-----------------------------\nExport has finished...\nLocal Date and Time: "+str(datetime.now())+"\n--------------------------***-----------------------------\n\n\n\n\n")
stderr.close()
stderr = __stderr__